package enumdemo;

public enum TestEnum {
    // 枚举对象
    RED("红色", 0),
    GREEN("绿色", 1),
    BLACK("黑色", 2),
    WHILE("白色", 2);

    public String color;
    public int ordinal;

    // 枚举的构造方法默认私有
//    TestEnum() {
//
//    }

    TestEnum(String color, int ordinal) {
        this.color = color;
        this.ordinal = ordinal;
    }

    public static void main(String[] args) {
        TestEnum test = TestEnum.valueOf("GREEN");
        System.out.println(test);

        System.out.println(RED.compareTo(GREEN)); // 0-1
        System.out.println(RED.compareTo(WHILE)); // 0-3
    }

    public static void main2(String[] args) {
        // values在
        TestEnum[] testEnums = TestEnum.values();

        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i] + "->" + testEnums[i].ordinal());
        }
    }

    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.BLACK;
        switch (testEnum) {
            case RED:
                System.out.println("red");
                break;
            case GREEN:
                System.out.println("green");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case WHILE:
                System.out.println("while");
                break;
            default:
                break;
        }
    }

}
